package com.lxmes.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.business.domain.NcWorkInstructionManagement;
import com.lxmes.business.service.INcWorkInstructionManagementService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 作业指导书管理Controller
 * 
 * @author lx
 * @date 2023-06-01
 */
@Api(tags = "作业指导书管理")    
@RestController
@RequestMapping("/business/NcWorkInstructionManagement")
public class NcWorkInstructionManagementController extends BaseController
{
    @Autowired
    private INcWorkInstructionManagementService ncWorkInstructionManagementService;

    /**
     * 查询作业指导书管理列表
     */
    @ApiOperation("查询作业指导书管理列表")
    @PreAuthorize("@ss.hasPermi('business:NcWorkInstructionManagement:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcWorkInstructionManagement ncWorkInstructionManagement)
    {
        startPage();
        List<NcWorkInstructionManagement> list = ncWorkInstructionManagementService.selectNcWorkInstructionManagementList(ncWorkInstructionManagement);
        return getDataTable(list);
    }

    /**
     * 导出作业指导书管理列表
     */
    @ApiOperation("导出作业指导书管理列表")
    @PreAuthorize("@ss.hasPermi('business:NcWorkInstructionManagement:export')")
    @Log(title = "作业指导书管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcWorkInstructionManagement ncWorkInstructionManagement)
    {
        List<NcWorkInstructionManagement> list = ncWorkInstructionManagementService.selectNcWorkInstructionManagementList(ncWorkInstructionManagement);
        ExcelUtil<NcWorkInstructionManagement> util = new ExcelUtil<NcWorkInstructionManagement>(NcWorkInstructionManagement.class);
        util.exportExcel(response, list, "作业指导书管理数据");
    }

    /**
     * 获取作业指导书管理详细信息
     */
    @ApiOperation("获取作业指导书管理详细信息")
    @PreAuthorize("@ss.hasPermi('business:NcWorkInstructionManagement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncWorkInstructionManagementService.selectNcWorkInstructionManagementById(id));
    }

    /**
     * 新增作业指导书管理
     */
    @ApiOperation("新增作业指导书管理")
    @PreAuthorize("@ss.hasPermi('business:NcWorkInstructionManagement:add')")
    @Log(title = "作业指导书管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcWorkInstructionManagement ncWorkInstructionManagement)
    {
        return toAjax(ncWorkInstructionManagementService.insertNcWorkInstructionManagement(ncWorkInstructionManagement));
    }

    /**
     * 修改作业指导书管理
     */
    @ApiOperation("修改作业指导书管理")
    @PreAuthorize("@ss.hasPermi('business:NcWorkInstructionManagement:edit')")
    @Log(title = "作业指导书管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcWorkInstructionManagement ncWorkInstructionManagement)
    {
        return toAjax(ncWorkInstructionManagementService.updateNcWorkInstructionManagement(ncWorkInstructionManagement));
    }

    /**
     * 删除作业指导书管理
     */
    @ApiOperation("删除作业指导书管理")
    @PreAuthorize("@ss.hasPermi('business:NcWorkInstructionManagement:remove')")
    @Log(title = "作业指导书管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncWorkInstructionManagementService.deleteNcWorkInstructionManagementByIds(ids));
    }
    /**
     * 导入作业指导书管理
     */
    @Log(title = "作业指导书管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<NcWorkInstructionManagement> util = new ExcelUtil<>(NcWorkInstructionManagement.class);
        List<NcWorkInstructionManagement> ncWorkInstructionManagementList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ncWorkInstructionManagementService.imporIteminfo(ncWorkInstructionManagementList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<NcWorkInstructionManagement> util = new ExcelUtil<>(NcWorkInstructionManagement.class);
        util.importTemplateExcel(response,"作业指导书管理");
    }
}
